<!DOCTYPE html>
<html lang="en">
	<head>
		<title>对账数据处理</title>
		<#include "../inc/header.ftl"/>
	</head>

	<body class="no-skin">

		<div class="main-container ace-save-state" id="main-container">

			<div class="main-content">
				<div class="main-content-inner">

					<div class="page-content">
						<div class="row">
							<div id="grid-main-data" class="col-xs-12">
								<table id="MainGrid" style="min-height: 500px"></table>
								<div id="toolbar">
									<div style="padding:8px">
                                        账户：<input id="bankidfind" name="bankidfind">
                                        收款日期：<input id="paybankdtfind" class="easyui-datebox" style="width:140px">&emsp;
                                        <a href="#" onclick="javascript:searchInfo()" class="easyui-linkbutton" iconCls="icon-search">查 询</a>

                                    </div>
                                    <div style="padding:8px 8px 4px">
                                        <a href="#" class="easyui-linkbutton" iconCls="icon-filter" onclick="javascript:preCheck()">预审</a>
                                        <a href="#" class="easyui-linkbutton" iconCls="icon-send" onclick="javascript:sendInfo()">发送</a>
                                        <a href="#" class="easyui-linkbutton" iconCls="icon-edit" onclick="javascript:checkInfo()">查看</a>
                                        <a href="#" class="easyui-linkbutton" iconCls="icon-print" onclick="javascript:exportInfo()">导出</a>

                                    </div>
								</div>
							</div>
						</div><!-- /.row -->
					</div><!-- /.page-content -->

                    <div id="SendBox-add" class="ui-dialog-content hide">
                        <div style="padding:8px">
                            复核用户编码：<input id="usercode" class="easyui-textbox" style="width:110px" data-options="required:true" >&emsp;
                            复核用户密码：<input id="userpwd" class="easyui-passwordbox" style="width:110px" data-options="required:true" >&emsp;
                            <a href="#" class="easyui-linkbutton" iconCls="icon-redo"  onclick="javascript:pageSendInfo()"><span  id="sendClean">确认发送</span></a>
                        </div>
                        <table id="SendMainGrid"></table>
                    </div>

                    <div id="SendBox-viewEdit" class="ui-dialog-content hide">
                        <table id="tableEdit"></table>
                    </div>
                </div>
			</div><!-- /.main-content -->
		</div><!-- /.main-container -->

		<!-- basic scripts -->
		<#include "../inc/basicjs.ftl"/>

		<!-- inline scripts related to this page -->
		<script type="text/javascript">
            //列表-------------------------------------------------
			jQuery(function($) {
                var curr_time = new Date();
                curr_time.setDate(curr_time.getDate()-1);
                var str = curr_time.getFullYear()+"-";
                str += curr_time.getMonth()+1+"-";
                str += curr_time.getDate();
                $('#paybankdtfind').datebox('setValue',str);

                $('#MainGrid').datagrid({
                    url: prefix + '/bill/bankcheckbill/findPrereSultsPage',
                    checkbox: true,
                    pagination: true,
                    fitColumns:true,
                    striped: true,
                    singleSelect: true,
                    loadMsg: "正在加载数据，请稍后...",
                    queryParams: {bankid:0,paybankdt:$('#paybankdtfind').val()},
                    columns:[[
                        {field: 'ck', checkbox: true},
                        { title: '账号', field: 'accountcode',width:200},
                        { title: '开户行名称', field: 'bankname',width:200},
                        { title: '日期', field: 'paybankdt',width:200},
                        { title: '余额', field: 'balance',width:200},
                        { title: '当日发生金额', field: 'day',width:200,formatter: function(value,row,index){
                                return row.inamt-row.outamt;
                            }},
                        { title: '收入金额', field: 'inamt',width:200},
                        { title: '支出金额', field: 'outamt',width:200},
                        { title: '预审状态', field: 'state',width:200,formatter: function(value,row,index){
                                return value == 0 ? '成功' : '失败';
                            }},
                    ]],
                    toolbar: '#toolbar',
                    onDblClickRow: function (index, data) {
                    },
                    onLoadSuccess: function (data) {
                        if (data.total == 0) {
                            $('#grid-main-data').find('.datagrid-body').html('<div style="text-align: center;font-size: 14px;padding: 20px 0;">查询无数据</div>');
                        }
                    }
                });

                $(window).resize(function() {
                    $('#MainGrid').datagrid('resize');
                });
                //收款银行下拉框
                $('#bankidfind').combogrid({
                    panelWidth:550,
                    idField:'bankid',
                    textField:'accountname',
                    data: _bankdata,
                    columns:[[
                        {field: 'ck', checkbox: true},
                        {field:'cantonname',title:'区划',width:80},
                        {field:'accountcode',title:'账号',width:160},
                        {field:'bankname',title:'开户行名称',width:260}
                    ]]
                });
			});

			function searchInfo() {
                var bankid = $('#bankidfind').val();
                var paybankdt = $('#paybankdtfind').val();
                if (bankid == '' && paybankdt == '') {
                    $.messager.alert('提示', '请选择账户或日期', 'info');
                    return;
                }
                $('#MainGrid').datagrid('load', {
                    bankid: bankid,
                    paybankdt: paybankdt
                });
			}

            // 查看
            function checkInfo() {
                var rows = $('#MainGrid').datagrid('getSelections');
                if (rows.length == 0) {
                    $.messager.alert('提示', '请选择要查看的数据', 'info');
                    return;
                }
                if (rows.length>1) {
                    $.messager.alert('提示', '查看操作不能多选', 'info');
                    return;
                }
                $( "#SendBox-viewEdit" ).removeClass('hide').dialog({
                    title: '&nbsp;查看详细信息',
                    iconCls:'icon-add',
                    width: 600,
                    height: 500,
                    modal: true,
                    buttons:[{
                        text:'关闭',
                        iconCls:'icon-cancel',
                        width:80,
                        plain:false,
                        handler:function(){$('#SendBox-viewEdit').dialog('close')}
                    }]
                });

                // 右侧表格
                $('#tableEdit').datagrid({
                    url: prefix + '/bill/bankcheckbill/selbankcheckdetail',
                    checkbox: true,
                    fitColumns:true,
                    striped: true,
                    singleSelect: true,
                    loadMsg: "正在加载数据，请稍后...",
                    queryParams: {bankid:rows[0].bankid,paybankdt:rows[0].paybankdt},
                    columns:[[
                        { title: '业务', field: 'optername',width:100},
                        { title: '笔数', field: 'num',width:100},
                        { title: '金额', field: 'amt',width:120}
                    ]],
                });

            }


            // 预审
            function preCheck(){
                var bankid = $('#bankidfind').val();
                if(bankid==null||bankid==''){
                    $.messager.alert('提示', '请选择账户信息', 'info');
                    return;
                }
                var paybankdt = $('#paybankdtfind').val();
                if(paybankdt==null||paybankdt==''){
                    $.messager.alert('提示', '请选择日期信息', 'info');
                    return;
                }
                $.ajax({
                    url:prefix+'/bill/bankcheckbill/check',
                    type: 'POST',
                    data: {bankid:bankid,paybankdt:paybankdt},
                    success:function(data){
                        $.messager.alert('提示', data.msg, 'info');
                        searchInfo();
                    }
                });

            }


            //----------------------- 发送弹窗
            function sendInfo() {
                $('#usercode').textbox('setValue', '');
                $('#userpwd').textbox('setValue', '');
                var row = $('#MainGrid').datagrid('getSelected');
                if (row == null) {
                    $.messager.alert('提示', '请选择要发送的数据', 'info');
                    return;
                }
                
                if (row.state != 0) {
                    //$.messager.alert('提示', '不能发送预审失败的数据', 'info');
                    //return;
                }

                $( "#SendBox-add" ).removeClass('hide').dialog({
                    title: '&nbsp;确认余额发送消息',
                    iconCls:'icon-add',
                    width: 800,
                    height: 500,
                    modal: true,
                    buttons:[{
                        text:'取消',
                        iconCls:'icon-cancel',
                        width:80,
                        plain:false,
                        handler:function(){$('#SendBox-add').dialog('close')}
                    }]
                });


                // 右侧表格
                $('#SendMainGrid').datagrid({
                    url: prefix + '/bill/bankcheckbill/selbankcheckdetail',
                    checkbox: true,
                    fitColumns:true,
                    striped: true,
                    singleSelect: true,
                    loadMsg: "正在加载数据，请稍后...",
                    queryParams: {bankid:row.bankid,paybankdt:row.paybankdt},
                    columns:[[
                        { title: '业务', field: 'optername',width:100},
                        { title: '笔数', field: 'num',width:100},
                        { title: '金额', field: 'amt',width:120}
                    ]],
                });
            }
            //  ----------------确认发送
            function pageSendInfo() {
                var usercode = $('#usercode').val();
                var userpwd = $('#userpwd').val();
                if(usercode==null||usercode==''){
                    $.messager.alert('提示', '请输入用户编码', 'info');
                    return;
                }
                if(userpwd==null||userpwd==''){
                    $.messager.alert('提示', '请输入用户密码', 'info');
                    return;
                }

                var row = $('#MainGrid').datagrid('getSelected');
                var bankid = row.bankid;
                var paybankdt = row.paybankdt;

                $.messager.progress({
                   title: '提示',
                   msg: '数据处理中，请稍候……',
                   text: ''
                });
                $.ajax({
                    url: prefix +'/bill/bankcheckbill/sendBankCheckBill',
                    type: 'POST',
                    data: {
                        usercode: usercode,
                        userpwd:userpwd,
                        bankid:bankid,
                        paybankdt:paybankdt,
                        accountcode:row.accountcode
                    },
                    dataType: 'json',
                    success:function(data){
                        $.messager.alert('提示', data.msg, 'info', function() {
                            if (data.success) $('#SendBox-add').dialog('close');
                            $.messager.progress('close');
                        });
                    },
                    error : function(XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('提示', '提交失败', 'info');
                        $.messager.progress('close');
                    }
                });
            }

            function exportInfo() {
                var downurl = prefix + '/bill/bankcheckbill/findPrereSultsExport?1=1';

                var bankid = $('#bankidfind').val();
                var paybankdt = $('#paybankdtfind').val();
                if(bankid==''&&paybankdt==''){
                    $.messager.alert('提示', '请选择帐户或者日期', 'info');
                    return;
                }
                bankid == "" ? downurl = downurl : downurl = downurl + "&bankid=" + bankid;
                paybankdt == "" ? downurl = downurl : downurl = downurl + "&paybankdt=" + paybankdt;
                window.location.href = downurl;
            }


        </script>
	</body>
</html>
